﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game.Foundation.ChineseChess
{
    public class Bing : ChessmanBase
    {
        private int _flag;//进攻方向1,-1

        private int _yorignal;

        public Bing(Chessboard board, Camp camp, string text, int flag, int Yorignal)
            : base(board, camp, text)
        {
            this._flag = flag;
            this._yorignal = Yorignal;
        }


        public override bool CanMoveTo(int xLocation, int yLocation)
        {
            int xoffset = xLocation - this.XLocation;
            int yoffset = yLocation - this.YLocation;
            int yTotalOffset = yLocation - this._yorignal;

            if (xoffset * yoffset == 0 && Math.Abs(xoffset + yoffset) == 1)
            {
                if (Math.Abs(yTotalOffset) < 2)
                {
                    return yoffset * this._flag > 0;
                }

                if (Math.Abs(xoffset) == 1)
                {
                    return Math.Abs(yTotalOffset) >= 2;
                }
                else
                {
                    return yoffset == this._flag;
                }
            }

            return false;
        }
    }
}
